package com.example.controller;


import com.example.model.Category;
import com.example.model.Product;
import com.example.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping
public class IndexController {

    @Autowired
    CategoryService categoryService;
    @RequestMapping("")
    public String index(Model model) throws Exception {
//        Pagination pagination = new Pagination();
//        pagination.setCount(13);
        List<Category> categories = categoryService.caList();//拿到全部的类
//        categories.add(new Category(1,"测试"));

//        for (int i = 0; i < 21; i++) {
//            Category c = new Category(2,"测试分类"+i);
//            List<Product> p = new ArrayList<>();
//            for (int j=0;j<10;j++){
//
//                p.add(new Product(Long.valueOf(j+""),"j"+j,100,"img/logo.png",100,2,60000,120));
//            }
//            c.setProducts(p);
//            categories.add(c);
//
//        }


//        for(Category category:categories){
//            category.setProducts(productService
//                    .list("cid",category.getId(),"stock_gt",0));
//        }
        model.addAttribute("categories",categories);
        return "index";
    }
}
